﻿using Engine;
using Game;
using System.Collections.Generic;
namespace Mekiasm
{
    public class ElectricPumpWidget : BaseEnergyWidget
    {
        public ComponentElectricPump Component;
        public InventorySlotWidget inventory;
        public string containerName;
        public FluidBaseProgress FluidBaseProgress;
        public ComponentEnergyMachine.Slot Slot;
        public StackPanelWidget mStackCenter = new StackPanelWidget() { Direction = LayoutDirection.Vertical, HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center };
        public ElectricPumpWidget(ComponentElectricPump componentMekPump, ComponentMiner componentMiner) : base(componentMiner)
        {
            Component = componentMekPump;
            Slot = Component.Slots[0];
            FluidBaseProgress = new FluidBaseProgress(new Vector2(40, 120), Slot);
            inventory = new InventorySlotWidget() { Size = new Vector2(48, 48), BevelColor = Color.Red };
            inventory.AssignInventorySlot(componentMekPump, 0);
            mStackCenter.Children.Add(inventory);
            CanvasWidget canvasWidget = new CanvasWidget() { Size = new Vector2(60, 20) };
            mStackCenter.Children.Add(canvasWidget);
            CanvasMain.Children.Add(mStackCenter);
            CanvasMain.Children.Add(FluidBaseProgress);
            setTitle("电动泵");
            FluidBaseProgress.Margin = new Vector2(40, 0);
            FluidBaseProgress.SetProgress(0);
        }

        public override void Update()
        {
            int c = Terrain.ExtractContents(Slot.FuelValue);
            if (c == 0) { containerName = "无"; }
            else containerName = BlocksManager.Blocks[c].GetDisplayName(null, Slot.FuelValue);
            SetPowerProgress((float)Component.Power / Component.MaxPower);
            SetLeftBottomMoreInfo($"最大储存:{ILibrary.FormatFluid(Slot.FuelCapacity)}\n能量消耗:{ILibrary.FormatPower(Component.OutputPowerLimit, "J")}\n能量储存:{ILibrary.FormatPower(Component.Power)}\n最大能量:{ILibrary.FormatPower(Component.MaxPower)}");
            FluidBaseProgress.SetProgress((float)Component.Slots[0].FuelAmount / Component.Slots[0].FuelCapacity);
        }

    }
}
